package com.nineclock.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nineclock.common.utils.BeanHelper;
import com.nineclock.system.dto.SysCommonIndustryDTO;
import com.nineclock.system.mapper.SysIndustryMapper;
import com.nineclock.system.pojo.SysCommonIndustry;
import com.nineclock.system.service.SysIndustryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SysIndustryServiceImpl implements SysIndustryService {

    @Autowired(required = false)
    private SysIndustryMapper industryMapper;

    @Override
    public List<SysCommonIndustryDTO> queryIndustryList(Long parentId) {
        LambdaQueryWrapper<SysCommonIndustry> wrapper = new LambdaQueryWrapper<>();
        if(parentId==null){
            wrapper.between(SysCommonIndustry::getParentId,'A','Z');
        }else{
            wrapper.eq(SysCommonIndustry::getParentId,parentId);
        }

        List<SysCommonIndustry> industryList = industryMapper.selectList(wrapper);
        return BeanHelper.copyWithCollection(industryList,SysCommonIndustryDTO.class);
    }
}
